package com.qys.livesMall.shop.open.anchor.service;

import com.qys.livesMall.shop.open.anchor.mapper.AnchorOpenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @menu AnchorServer
 * @date 2023/08/14 13:55
 */
@Service
public class AnchorServer {


    @Autowired
    private AnchorOpenMapper anchorOpenMapper;

    public Map<Long, BigDecimal> getAnchorCommissionRate(List<Long> anchorIds){
        if (CollectionUtils.isEmpty(anchorIds)){
            return new HashMap<>();
        }
        List<Map<String,Object>> list= anchorOpenMapper.getAnchorCommissionRate(anchorIds);
        if (CollectionUtils.isEmpty(list)){
            return new HashMap<>();
        }
        Map<Long,BigDecimal> rateMap=new HashMap<>();
        for(Map<String,Object> r:list){
            if (r.get("clearingForm")!=null&&(Integer)r.get("clearingForm")==1){
                //底薪结算
                rateMap.put((Long)r.get("id"),null);
                continue;
            }
            BigDecimal rate=(BigDecimal) r.get("rate");
            if (rate==null){
                rate=new BigDecimal("0");
            }
            rateMap.put((Long)r.get("id"),rate);
        }
        return rateMap;
    }

    public Long getAnchorUserId(Long id){
        return anchorOpenMapper.getUserId(id);
    }

    public Map<String, Object> getAnchor(Long anchorId) {
        return anchorOpenMapper.getAnchor(anchorId);
    }

    /**
     * 根据直播场次id获取直播间编号
     * @param sessionId
     * @return
     */
    public String getRoomInfoByLivesSessionId(Long sessionId){
        return anchorOpenMapper.getRoomInfoByLivesSessionId(sessionId);
    }

    public Long getAnchorIdByTaskId(Long taskId){
        return anchorOpenMapper.getAnchorIdByTaskId(taskId);
    }
}

